import 'package:flutter/cupertino.dart';
import 'package:yw_bapp/model/block_money_model.dart';
import 'package:yw_bapp/model/order_list_model.dart';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:yw_bapp/utils/loacl_storage.dart';

const BASER_URL = "https://ywapidev.lemobj.com/api/";
var headerMap = new Map<String, String>.from(
    {"content-type": "application/json", "X-YOUWEI-PLAT": 'wx_b_user'});
//  获取订单列表接口地址
const orderListURL = BASER_URL + "manager/account/order/list?page=";

// 获取冻结金额接口地址
const blockMoneyURL = BASER_URL + "manager/account/get_block_apply_money";

// 账户、订单相关的接口
class OrderDao {
// 获取订单列表接口
  static Future<OrderListModel> GetOrderList(pageIndex) async {
    var storeID = await getStorage('Store-ID');
    var token = await getStorage('Token');
    // headerMap['Token'] = token.toString();
    // headerMap['Store-ID'] = storeID.toString();
    headerMap['Token'] = '529';
    headerMap['Store-ID'] = '226';
    final response =
        await http.get(orderListURL + '$pageIndex', headers: headerMap);
    if (response.statusCode == 200) {
      // 解决中文乱码
      Utf8Decoder utf8decoder = Utf8Decoder();
      var result = json.decode(utf8decoder.convert(response.bodyBytes));
      return OrderListModel.fromJson(result);
    } else {
      print('请求接口失败');
      throw Exception('请求接口失败');
    }
  }

  // 获取冻结金额接口
  static Future<BlockMoneyModel> GetBlockMoney() async {
    var storeID = await getStorage('Store-ID');
    var token = await getStorage('Token');
    // headerMap['Token'] = token.toString();
    // headerMap['Store-ID'] = storeID.toString();
    headerMap['Token'] = '529';
    headerMap['Store-ID'] = '226';
    final response = await http.get(blockMoneyURL, headers: headerMap);
    if (response.statusCode == 200) {
      // 解决中文乱码
      Utf8Decoder utf8decoder = Utf8Decoder();
      var result = json.decode(utf8decoder.convert(response.bodyBytes));
      return BlockMoneyModel.fromJson(result);
    } else {
      print('请求接口失败');
      throw Exception('请求接口失败');
    }
  }
}
